package com.auction.controller;

import com.auction.common.core.controller.MyBaseController;
import com.auction.common.dao.bean.PageResult;
import com.auction.common.utils.ReturnResult;
import com.auction.entity.Product;
import com.auction.mapper.ProductClassifyMapper;
import com.auction.mapper.ProductMapper;
import com.auction.query.ProductQuery;
import com.auction.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/api")
@RestController
@Api(tags = "商品详情")
public class ProductController extends MyBaseController {
    @Autowired
    ProductService productService;
    @Autowired
    ProductMapper productMapper;

    @Autowired
    ProductClassifyMapper productClassifyMapper;

    @ApiOperation("查询商品")
    @PostMapping("/query")
    public ReturnResult query(@RequestBody ProductQuery query) {
        PageResult result = productService.queryByPage(query);
        return success("商品列表", result);
    }


    @ApiOperation("添加商品")
    @PostMapping("/add")
    public ReturnResult save(@RequestBody Product product) {
        int rs = productService.saveEntity(product);
        return saveResult(rs);
    }


    @ApiOperation("修改商品")
    @PutMapping("/update")
    public ReturnResult update(@RequestBody Product product) {
        int rs = productService.updateEntity(product);
        return updateResult(rs);
    }

    @ApiOperation("删除商品")
    @DeleteMapping("/delete")
    public ReturnResult delete(@RequestParam(name = "id") Integer id) {
        int rs = productMapper.delete(id);
        return deleteResult(rs);
    }

    @ApiOperation("商品状态")
    @PostMapping("/product/status")
    public ReturnResult status(@RequestBody Product product) {
        int rs = productMapper.byIdStatus(product);
        return updateResult(rs);
    }

    @ApiOperation("根据id改变商品主图")
    @PostMapping("/product/picture")
    public ReturnResult picture(@RequestBody Product product) {
        int rs = productMapper.byIdByIdPicture(product);
        return updateResult(rs);
    }

    @ApiOperation("根据id查询产品")
    @PostMapping("/product/byIdP")
    public ReturnResult byIdP(@RequestParam(name = "id") Integer id) {

        Map p=productMapper.byIdP(id);
        return success("商品信息",p);
    }

    @ApiOperation("分类树")
    @PostMapping("/Classifys")
    public ReturnResult Classifys() {
        List<Map> list=productClassifyMapper.querysify(0);
        return success("分类树",list);
    }
    @ApiOperation("更新数据")
    @PutMapping("/pUpdate")
    public ReturnResult pUpdate(@RequestBody Product product) {
        int rs=productService.upP(product);
        return updateResult(rs);
    }

    @ApiOperation("查询产品")
    @PostMapping("/product/comm")
    public ReturnResult Comm(@RequestBody ProductQuery productQuery) {

        PageResult  p  =productService.selectComm(productQuery);
        return success("产品列表",p);
    }


}





